package acm.蓝桥4;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class 兰顿蚂蚁 {
    static int n, m;
    static boolean[][] maze;
    static int x, y;
    static int[][] dir = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};    //上右下左
    static int d = 0;    //方向
    static int step;

    public static void main(String[] args) {
        Reader sc = new Reader();
        n = sc.nextInt();
        m = sc.nextInt();
        maze = new boolean[n][m];
        for (int i = 0; i < maze.length; i++) {
            for (int j = 0; j < maze[0].length; j++) {
                maze[i][j] = sc.nextInt() == 1;
            }
        }
        x = sc.nextInt();
        y = sc.nextInt();
        d = getD(sc.next());
        step = sc.nextInt();
        for (int i = 0; i < step; i++) {
            if (maze[x][y]) {   //黑
                d = (d + 1) % 4;    //右转
            } else {            //白
                d = (d + 3) % 4;    //左转
            }
            maze[x][y] = !maze[x][y];    //反转颜色
            x += dir[d][0];
            y += dir[d][1];
            if (x < 0 || x >= n || y < 0 || y >= m) {
                return;
            }
        }
        System.out.println(x + " " + y);
    }

    public static int getD(String s) {
        switch (s) {
            case "U":
                return 0;
            case "R":
                return 1;
            case "D":
                return 2;
            default:
                return 3;
        }
    }
    static
    class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }
        public void clear(){
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}
